<template>
	<view class="container">
		<myNavigate @changecity="changecity" :cityname="cityname"></myNavigate>
		<view class="header-container">
			<view class="banner">
				<image class="banner-bg"   src="https://www.ggshop1688.com/upload/api-img/ptlb.jpg"></image>
				<image  class="banner-bg-bottom" src="/static/arc.png" ></image>
			</view>
		</view>
		<view class="sortlist">
			<myTab v-if="secCates.length>0" @tabClick="chikdClick" ref="mid" isCate border='#ee5b25' :tabs='secCates'></myTab>
		</view>
		<view class="goodsContain">
			<view class="goodContent">
				<block v-if="gifts.length">
					<view class="goodItem" v-for="(item,index) in gifts" :key="index" @click="toProduct(item.goodsId)">
						<image :src="item.goodsImg" class="goodsPic" mode=""></image>
						<view class="complateRow">
							<view class="comLeft">
								<view class="goodsName">
									{{item.goodsName}}
								</view>
								<view class="price">
									<text class="currPrice">￥{{item.shopPrice}}</text>
									<text class="thouLine">￥{{item.marketPrice}}</text>
								</view>
								<view class="express">
									<view class="expreTitle">消费奖励：{{item.rebate_gg_credit}}</view>
									
								</view>
								<view class="express">
									<view class="comRight">
										让利PV <text>￥{{item.rebatePv | parseIntFilter}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
				<empty v-if="showempty" emptyText="无对应礼包"></empty>
			</view>

			<uni-load-more v-if="needLoad" :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import myTab from "@/components/scrollTab/scrollTab.vue";
	import myNavigate from "@/components/myNavigateBar/myNavigateBar.vue"
	import empty from "@/components/empty.vue"
	export default {
		components: {
			myNavigate,
			myTab,
			empty,
			uniLoadMore
		},
		data() {
			return {
				goodsCatId: '',
				page: '1',
				loading: false,
				loadingType: 'more',
				isdone: false,
				needLoad: true,
				showempty: false,
				secCates: [],
				gifts: [],
				cityname: '获取定位',
				shopId: '',
			};
		},
		onLoad(options) {
			if (uni.getStorageSync('mycity')) {
				this.cityname = uni.getStorageSync('mycity')
			} else {

			}
			if (options.shopId) {
				this.shopId = options.shopId
			}
			this.getsortlist();
		},
		// filters: {
		// 	parseIntFilter(num) {
		// 		var moneyNum = +num;
		// 		if (!num) {
		// 			moneyNum = 0;
		// 			return parseInt(moneyNum);
		// 		} else if (isNaN(moneyNum)) {
		// 			return "-";
		// 		} else {
		// 			return parseInt(moneyNum);
		// 		}
		// 	}
		// },
		methods: {
			onReachBottom() {
				let that = this;
				if (that.isdone) {
					return false;
				}
				that.loading = true;
				that.page++;
				that.loadingType = 'loading';
				that.loadgiftlist();
			},
			getsortlist() {
				let that = this;
				let data = {
					shopId: this.shopId
				}
				that.$Request.request('/api/goods/giftBagCatList', 'GET', data).then(res => {
					if (res.status == 1) {
						this.secCates = res.data.list;
						this.goodsCatId = res.data.list[0].catId
						this.loadgiftlist()
					}
				})
			},
			chikdClick(data) {
				console.log(data)
				this.goodsCatId = data.item.catId
				this.gifts = [];
				this.isdone = false;
				this.page = 1;
				this.loadgiftlist()
			},
			changecity(e) {
				this.cityname = e;
			},
			// loadgiftlist() {
			// 	let that = this;
			// 	let data = {

			// 	}
			// 	that.$Request.request('/api/goods/giftBagList', 'GET').then(res => {
			// 		that.gifts = res.data.list;
			// 	})
			// },
			loadgiftlist() {
				let that = this;
				console.log(that.isdone, '2')
				if (that.isdone) {
					return false;
				}
				// if(iswaitload){
				// 	return false;
				// }
				console.log(this.shopId)
				let data = {}
				if (that.shopId != '') {
					data.shopId = this.shopId
					data.goodsCatId = that.goodsCatId
					data.latitude = getApp().globalData.globa_latitude
					data.longitude = getApp().globalData.globa_longitude
					data.p = that.page
				} else {
					data.goodsCatId = that.goodsCatId
					data.latitude = getApp().globalData.globa_latitude
					data.longitude = getApp().globalData.globa_longitude
					data.p = that.page
				}

				that.$Request.request('/api/goods/giftBagList', 'GET', data).then(res => {
					if (res.status == 1) {

						res.data.list.forEach(item => {
							that.gifts.push(item)
						})
						that.loadingType = 'more'
						if (res.data.list.length < 20) {
							that.loading = true;
							that.isdone = true;
							that.loadingType = 'noMore'
						}

						that.gifts.length == 0 ? [this.showempty = true, this.needLoad = false] : [this.showempty = false, this.needLoad =
							true
						]
					}
					console.log(that.gifts)
				}).catch(err => {
					console.log(err)
				})
			},
			toProduct(id) {
				uni.navigateTo({
					url: '../../pages/product/product?isgift=1' + '&id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goodsPic{
		width: 260upx;
		height: 260upx;
	}
	.sortlist {
		padding: 20upx;
		background-color: #fff;
	}

	@import './giftPackage.scss';
</style>
